import { reactive, ref } from "vue";
import { ElForm } from "element-plus";
import { usePage } from "@/hook/usePage";
import { panellists } from "@/api/api";
//表单
export const useRewardForm = () => {
  const rewardForm = reactive({
    timeRadio: "1",
    time: "",
  });

  const rewardFormRef = ref<Nullable<typeof ElForm>>(null);
  const resetForm = () => {
    rewardForm.time = "";
    rewardFormRef.value!.resetFields();
  };
  //时间参数
  const c_time = () => {
    let time;
    //今日实时
    if (rewardForm.timeRadio == "1") {
      const now = new Date();
      const nowTime = {
        startTime: `${now.getFullYear()}-${
          now.getMonth() + 1
        }-${now.getDate()}`,
        endTime: `${now.getFullYear()}-${now.getMonth() + 1}-${now.getDate()}`,
      };
      time = nowTime;
    }
    // 指定范围
    else {
      const startTime = new Date(rewardForm.time[0]);
      const endTime = new Date(rewardForm.time[1]);
      time = {
        startTime: `${startTime.getFullYear()}-${
          startTime.getMonth() + 1
        }-${startTime.getDate()}`,
        endTime: `${endTime.getFullYear()}-${
          endTime.getMonth() + 1
        }-${endTime.getDate()}`,
      };
    }
    return time;
  };
  return {
    resetForm,
    rewardFormRef,
    rewardForm,
    c_time,
  };
};
export const useRewardPage = () => {
  const { info, requestApi } = usePage(panellists);
  const resetTable = (page_size = 5) => {
    info.params.page = 1;
    info.total = 0;
    info.params.page_size = page_size;
  };
  return {
    info,
    requestApi,
    resetTable,
  };
};
